home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / util / seticons.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-01-29  |  3.8 KB  |  159 lines

  1. /* seticons.c - sets icon configuration in WindowMaker
  2.  *
  3.  *  WindowMaker window manager
  4.  * 
  5.  *  Copyright (c) 1997, 1998 Alfredo K. Kojima
  6.  * 
  7.  *  This program is free software; you can redistribute it and/or modify
  8.  *  it under the terms of the GNU General Public License as published by
  9.  *  the Free Software Foundation; either version 2 of the License, or
  10.  *  (at your option) any later version.
  11.  *
  12.  *  This program is distributed in the hope that it will be useful,
  13.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15.  *  GNU General Public License for more details.
  16.  *
  17.  *  You should have received a copy of the GNU General Public License
  18.  *  along with this program; if not, write to the Free Software
  19.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  20.  *  USA.
  21.  */
  22.  
  23. #define PROG_VERSION "seticons (Window Maker) 0.1"
  24.  
  25.  
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <proplist.h>
  29.  
  30. #include <string.h>
  31.  
  32. #include "../src/wconfig.h"
  33.  
  34. char *ProgName;
  35.  
  36. char*
  37. defaultsPathForDomain(char *domain)
  38. {
  39.     char path[1024];
  40.     char *gspath, *tmp;
  41.  
  42.     gspath = getenv("GNUSTEP_USER_ROOT");
  43.     if (gspath) {
  44.     strcpy(path, gspath);
  45.     strcat(path, "/");
  46.     } else {
  47.     char *home;
  48.     
  49.     home = getenv("HOME");
  50.     if (!home) {
  51.         printf("%s:could not get HOME environment variable!\n", ProgName);
  52.         exit(0);
  53.     }
  54.  
  55.     strcpy(path, home);
  56.     strcat(path, "/GNUstep/");
  57.     }
  58.     strcat(path, DEFAULTS_DIR);
  59.     strcat(path, "/");
  60.     strcat(path, domain);
  61.  
  62.     tmp = malloc(strlen(path)+2);
  63.     strcpy(tmp, path);
  64.     
  65.     return tmp;
  66. }
  67.  
  68.  
  69. void
  70. print_help()
  71. {
  72.     printf("Usage: %s [OPTIONS] FILE\n", ProgName);
  73.     puts("Reads icon configuration from FILE and updates Window Maker.");
  74.     puts("");
  75.     puts("  --help    display this help and exit");
  76.     puts("  --version    output version information and exit");
  77. }
  78.  
  79.  
  80. int 
  81. main(int argc, char **argv)
  82. {
  83.     proplist_t window_name, icon_key, window_attrs, icon_value;
  84.     proplist_t all_windows, iconset;
  85.     proplist_t keylist;
  86.     int i;
  87.     char *path = NULL;
  88.  
  89.     ProgName = argv[0];
  90.  
  91.  
  92.     if (argc < 2) {
  93.     printf("%s: missing argument\n", ProgName);
  94.     printf("Try '%s --help' for more information\n", ProgName);
  95.     }
  96.  
  97.     for (i = 1; i < argc; i++) {
  98.     if (strcmp(argv[i], "-h")==0
  99.         || strcmp(argv[i], "--help")==0) {
  100.         print_help();
  101.         exit(0);
  102.     } else if (strcmp(argv[i], "--version")==0) {
  103.         puts(PROG_VERSION);
  104.         exit(0);
  105.     } else {
  106.         if (path) {
  107.         printf("%s: invalid argument '%s'\n", ProgName, argv[i]);
  108.         printf("Try '%s --help' for more information\n", ProgName);
  109.         exit(1);
  110.         }
  111.         path = argv[i];
  112.     }
  113.     }
  114.     
  115.     path = defaultsPathForDomain("WMWindowAttributes");
  116.     
  117.     all_windows = PLGetProplistWithPath(path);
  118.     if (!all_windows) {
  119.     printf("%s:could not load WindowMaker configuration file \"%s\".\n", 
  120.            ProgName, path);
  121.     exit(1);
  122.     }
  123.  
  124.     iconset = PLGetProplistWithPath(argv[1]);
  125.     if (!iconset) {
  126.     printf("%s:could not load icon set file \"%s\".\n", ProgName, argv[1]);
  127.     exit(1);
  128.     }
  129.  
  130.     
  131.     keylist = PLGetAllDictionaryKeys(iconset);
  132.     icon_key = PLMakeString("Icon");
  133.     
  134.     for (i=0; i<PLGetNumberOfElements(keylist); i++) {    
  135.     window_name = PLGetArrayElement(keylist, i);
  136.     if (!PLIsString(window_name))
  137.         continue;
  138.  
  139.     icon_value = PLGetDictionaryEntry(iconset, window_name);
  140.     if (!icon_value || !PLIsDictionary(icon_value))
  141.         continue;
  142.  
  143.     window_attrs = PLGetDictionaryEntry(all_windows, window_name);
  144.     if (window_attrs) {
  145.         if (PLIsDictionary(window_attrs)) {
  146.         PLMergeDictionaries(window_attrs, icon_value);
  147.         }
  148.     } else {
  149.         PLInsertDictionaryEntry(all_windows, window_name, icon_value);
  150.     }
  151.     }
  152.     
  153.     PLSave(all_windows, YES);
  154.  
  155.     exit(0);
  156. }
  157.  
  158.  
  159.